package cn.gok.util;

import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * @ClassName ArrayList
 * @Description TODO
 * @Author HP
 * @Date 14:03 2022/7/8
 * @Version 1.0
 **/

public class ArrayList的例子 {
    public static void main(String[] args) {
        常用方法();
        四种迭代方法();
    }

    private static void 四种迭代方法() {
        List<String> list = Arrays.asList("aaa", "bbb", "ccc", "ddd");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println(" ");

        for (String string : list) {
            System.out.println(string + "");
        }
        System.out.println("");
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
            String str = it.next();
            System.out.println(str);
        }
        list.stream().forEach((String e)->{
            System.out.println(e+"");
        });
        list.stream().forEach(e->System.out.println(e+""));
        list.stream().forEach(System.out::println);
    }

    private static void 常用方法() {
        ArrayList<Float> floats = new ArrayList<>();
        floats.add(0.1f);
        floats.add(0.2f);
        floats.add(0.3f);
        floats.set(floats.indexOf(0.2f), 0.6f);

        floats.remove(floats.size() - 1);
        System.out.println(floats.size());


    }
}
